package com.nutrition.health.repository;

import com.nutrition.health.model.NutritionInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface NutritionInfoRepository extends JpaRepository<NutritionInfo, Long> {
    
    Optional<NutritionInfo> findByFoodItemId(Long foodItemId);
    
    @Query("SELECT n FROM NutritionInfo n WHERE " +
           "n.calories BETWEEN :minCalories AND :maxCalories")
    List<NutritionInfo> findByCalorieRange(
            @Param("minCalories") Double minCalories, 
            @Param("maxCalories") Double maxCalories);
    
    @Query("SELECT n FROM NutritionInfo n WHERE " +
           "n.protein >= :minProtein AND " +
           "n.carbohydrates <= :maxCarbs AND " +
           "n.fat <= :maxFat")
    List<NutritionInfo> findByNutrientConstraints(
            @Param("minProtein") Double minProtein,
            @Param("maxCarbs") Double maxCarbs,
            @Param("maxFat") Double maxFat);
}